using YMJake.Flowable.ExternalWorker.Client.Core.Client;

namespace YMJake.Flowable.ExternalWorker.Client.AspNetCore.Pipeline;

/// <summary>
/// Implementation of worker pipeline context
/// </summary>
public class WorkerPipelineContext : IWorkerPipelineContext
{
    public IAcquiredExternalWorkerJob Job { get; }
    public string Topic { get; }
    public string WorkerId { get; }
    public IServiceProvider ServiceProvider { get; }
    public IWorkResultBuilder ResultBuilder { get; }
    public WorkerResult? Result { get; set; }
    public IDictionary<string, object?> Properties { get; } = new Dictionary<string, object?>();
    public CancellationToken CancellationToken { get; }

    public WorkerPipelineContext(
        IAcquiredExternalWorkerJob job,
        string topic,
        string workerId,
        IServiceProvider serviceProvider,
        IWorkResultBuilder resultBuilder,
        CancellationToken cancellationToken = default)
    {
        Job = job ?? throw new ArgumentNullException(nameof(job));
        Topic = topic ?? throw new ArgumentNullException(nameof(topic));
        WorkerId = workerId ?? throw new ArgumentNullException(nameof(workerId));
        ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
        ResultBuilder = resultBuilder ?? throw new ArgumentNullException(nameof(resultBuilder));
        CancellationToken = cancellationToken;
    }
}